﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;

namespace PA3PC113
{
  public class Makelog
    {
      public void MakeLog(int logkind, string Msg1, string Msg2)
      {
          FileStream fs = null;
          StreamWriter fileWrite = null;
          string LogPath = string.Empty;
          //string LogPath = System.Environment.CurrentDirectory + "\\messagelog_tsg.txt";
          //Recoder
          if (logkind == 1)
          {
              string RecoderLogPath = Convert.ToString(ConfigurationManager.AppSettings.GetValues("RecoderLogPath")[0]);
              LogPath = @"" + RecoderLogPath + "" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
          }
          //errorlog
          else if (logkind == 2)
          {
              string RecoderLogPath = Convert.ToString(ConfigurationManager.AppSettings.GetValues("ErrorLogPath")[0]);
              LogPath = @"" + RecoderLogPath + "" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
          }
          if (!File.Exists(LogPath))
          {
              fs = new FileStream(LogPath, FileMode.Create, FileAccess.Write);
          }
          else
          {
              fs = new FileStream(LogPath, FileMode.Append, FileAccess.Write);
          }
          fileWrite = new StreamWriter(fs, Encoding.Default);
          fileWrite.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Msg1 + ":" + Msg2);
          fileWrite.WriteLine("\r\n");
          fileWrite.Close();
          fs.Close();
      }
    }
}
